package com.wyx.suanfa;

/**
 * @author 王艺锡
 * @version 1.0
 */
public class sortList {
    //给你链表的头结点 head ，请将其按 升序 排列并返回 排序后的链表 。
    public static void main(String[] args) {


    }
}
/*
* /**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode() {}
 *     ListNode(int val) { this.val = val; }
 *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */
/*
class Solution {
    public ListNode sortList(ListNode head) {
        if(head == null || head.next == null){
            return head;
        }
        //使用快慢指针寻找中间点
        ListNode fast = head;
        ListNode slow = head;
        while(fast.next != null && fast.next.next != null){
            fast = fast.next.next;
            slow = slow.next;
        }

        //找到中间点进行递归
        fast = slow.next;
        slow.next = null;
        ListNode left = sortList(head);
        ListNode right = sortList(fast);

        ListNode vHead = new ListNode(-1);
        ListNode cur = vHead;
        //合并两个有序链表
        while(left != null && right != null){
            if(left.val <= right.val){
                cur.next = left;
                left = left.next;
            }else{
                cur.next = right;
                right = right.next;
            }
            cur = cur.next;
        }
        cur.next = left != null? left : right;
        return vHead.next;
    }
}*/